package com.huiying.controller;


import com.huiying.entity.dto.WorkDTO;
import com.huiying.entity.dto.WorkPageQueryDTO;
import com.huiying.entity.result.PageResult;
import com.huiying.entity.result.Result;
import com.huiying.entity.vo.WorkVO;
import com.huiying.service.WorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: lsh
 * @Date: 2024/12/03/21:05
 * @Description: 作品模块控制器
 */
@RestController
@Api(tags = "作品相关接口")
@Slf4j
@RequestMapping("/user/work")
public class WorkController {
    @Autowired
    private WorkService workService;

    /**
     *
     * @param workDTO 作品数据传输类
     * @return: com.fx.result.Result
     */
    @ApiOperation("新增作品")
    @PostMapping("/add")
    public Result addWork(@RequestBody WorkDTO workDTO){
        log.info("用户新增作品");
        workService.addWork(workDTO);
        return Result.success();
    }

    /**
     * 根据id查询作品
     * @param workId 作品id
     * @return: com.fx.result.Result<com.fx.vo.WorkVO>
     */
    @ApiOperation("根据id查询作品")
    @GetMapping("/getById")
    public Result<WorkVO> getById(Long workId){
        log.info("查询作品:{}",workId);
        WorkVO workVO = workService.getById(workId);
        return Result.success(workVO);
    }

    /**
     * 作品分页查询
     * @param workPageQueryDTO 作品分页查询数据传输对象
     * @return: com.fx.result.Result<com.fx.result.PageResult>
     */
    @GetMapping("/page")
    @ApiOperation("作品分页查询")
    public Result<PageResult> pageQuery(WorkPageQueryDTO workPageQueryDTO){
        log.info("作品分页查询{}",workPageQueryDTO);

        PageResult pageResult = workService.pageQuery(workPageQueryDTO);

        return Result.success(pageResult);
    }

    /**
     * 修改作品
     * @param workDTO 作品数据传输类
     * @return: com.fx.result.Result
     */
    @PutMapping("/update")
    @ApiOperation("修改作品")
    public Result update(@RequestBody WorkDTO workDTO){
        log.info("修改作品{}",workDTO.getId());
        workService.updateWork(workDTO);
        return Result.success();
    }

    /**
     * 删除作品
     * @param wordId 作品id
     * @return: com.fx.result.Result
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除作品")
    public Result delete(Long wordId){
        log.info("删除作品{}",wordId);
        workService.deleteWork(wordId);
        return Result.success();
    }

}

